package org.edu.modules.growth.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.api.vo.Result;
import org.edu.common.system.base.controller.BaseController;
import org.edu.modules.growth.dto.VeJsczExamProjectDTO;
import org.edu.modules.growth.entity.VeJsczExamProject;
import org.edu.modules.growth.service.IVeJsczExamProjectService;
import org.edu.modules.growth.vo.QueryCondition;
import org.edu.modules.growth.vo.VeJsczExamProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="教职工评价管理--评价项目管理")
@RestController
@RequestMapping("jsczExamProject")
@Slf4j
@AllArgsConstructor
public class VeJsczExamProjectController extends BaseController<VeJsczExamProject, IVeJsczExamProjectService> {

    private IVeJsczExamProjectService mIVeJsczExamProjectService;

    @ApiOperation(value = "保存与编辑评价项目")
    @PostMapping("/addOrUpdate")
    public Result<?> addOrUpdate(@RequestBody VeJsczExamProjectDTO veJsczExamProjectDTO) {
        VeJsczExamProject project = new VeJsczExamProject() ;
        BeanUtils.copyProperties(veJsczExamProjectDTO,project);
        if( veJsczExamProjectDTO.getId() != null ){
            Integer score = mIVeJsczExamProjectService.availableScore(veJsczExamProjectDTO.getId()) ;
            if( score.equals( project.getScore() ) ){
                project.setEnable(1) ;
            }else{
                project.setEnable(0) ;
            }
            return Result.OK(mIVeJsczExamProjectService.updateById(project));
        }
        project.setTerminalId(1L) ;
        return Result.OK(mIVeJsczExamProjectService.save(project));
    }

    @ApiOperation(value = "分页查询信息")
    @PostMapping("/selectPage")
    public Result<?> selectPage(@RequestBody QueryCondition queryCondition ) {
        return Result.OK(mIVeJsczExamProjectService.selectPage(queryCondition));
    }

    @ApiOperation(value = "获取评价项目信息")
    @PostMapping("/getDetail")
    public Result<VeJsczExamProject> getDetail(@RequestParam("id") Long id) {
        return Result.OK(mIVeJsczExamProjectService.getById(id));
    }

    @ApiOperation(value = "获取评价项目详情信息（包含评价指标信息）")
    @PostMapping("/getDetailInfo")
    public Result<VeJsczExamProjectVo> getDetailInfo(@RequestParam("id") Long id) {
        return Result.OK(mIVeJsczExamProjectService.getDetailInfo(id));
    }

    @ApiOperation(value = "删除")
    @PostMapping("/removeById")
    public Result<?> removeById(@RequestParam("id") Long id) {
        return Result.OK( mIVeJsczExamProjectService.removeById(id) );
    }

    @ApiOperation(value = "批量删除")
    @PostMapping("/removeByIds")
    public Result<?> removeByIds(@RequestParam("ids") List<Long> ids) {
        return Result.OK(mIVeJsczExamProjectService.removeByIds(ids));
    }


    @ApiOperation(value = "发起评教页面查询评教项目信息")
    @PostMapping("/selectProjectByPut")
    public Result<?> selectProjectByPut(@RequestParam("type")String type,
                                        @RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize) {
        return Result.OK(mIVeJsczExamProjectService.selectProjectByStageId(Integer.parseInt(type),pageNum,pageSize));
    }


}
